<template>
    <div>
        <h2>登录</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">姓名</td>
                    <td><input type="text" v-model="info.username"></td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td><input type="password" v-model="info.userPwd"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="登录" @click="login"></td>
                </tr>
            </tbody>
        </table>
       
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted}from 'vue'
import axios from 'axios'; 
import moment from 'moment';
import{useRoute,useRouter}from 'vue-router'
import{useStore}from '@/stores/user'
const route=useRoute();
const router=useRouter();
const uStore=useStore();

let info:any=reactive({
    username:'',
    userPwd:'',
})
const login=()=>{
    if(info.username==""){
        alert("姓名不能为空");
        return;
    }
    if(info.userPwd==""){
        alert("密码不能为空");
        return;
    }
    axios({
        url:'/api/Admin/Login',
        method:'post',
        params:info
    })
    .then((res)=>{
        if(res.data==-1){
            alert("用户不存在");
            return;
        }
         if(res.data==-2){
            alert("密码错误");
            return;
        }
        else
        {
            alert("登录成功");
            //存储用户信息
            uStore.userInfo=res.data;
            router.push("/adminAdd");
            return;
        }
    })
}
</script>

<style scoped>

</style>